<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\xs\model;

use think\Model;
use app\xs\model\CmfRoleModel;

class CmfRoleUserModel extends Model
{
    /**
     * 模型名称
     * @var string
     */
    protected $name = 'role_user';

    /**
     * 根据用户id号，返回用户的角色
     * @param int
     * @return array
     */
    public function getRoleArrByUserID($userId){
        $res = $this->where("user_id",$userId)->column('role_id');

        if (empty($res)) return null;
        
        $crm = new CmfRoleModel();
        $where[] = ['id','in',$res];
        $where[] = ['status', '=', 1];
        $roleArr = $crm->where($where)->order("list_order","asc")->select()->toArray();

        return $roleArr;
    }



}
